// api/family/pet.ts
import { api } from '@/api/request'
import type { PageData, PageQuery } from '@/types'

// 宠物信息模型
export interface PetInfo {
    id: number
    name: string
    type: string  // 宠物类型: dog, cat, bird, fish, rabbit, other
    breed: string  // 品种
    age: number  // 年龄(岁)
    gender: string  // 性别: male, female
    health_status: string  // 健康状态: healthy, need_attention, under_treatment
    vaccine_status: string  // 疫苗情况: vaccinated, pending, not_vaccinated
    last_checkup: string  // 上次体检时间
    total_expense: number  // 累计医疗花销(元)
    notes: string  // 备注信息
    user_id: number
    family_id: number
    created_at: string
    updated_at: string
}

// 宠物查询参数
export interface PetQuery extends PageQuery {
    name?: string
    type?: string
    health_status?: string
}

// 创建宠物请求参数
export interface CreatePetRequest {
    name: string
    type: string
    breed?: string
    age: number
    gender: string
    health_status: string
    vaccine_status: string
    last_checkup?: string
    total_expense?: number
    notes?: string
    user_id: number
    family_id: number
}

// 更新宠物请求参数
export interface UpdatePetRequest {
    name?: string
    type?: string
    breed?: string
    age?: number
    gender?: string
    health_status?: string
    vaccine_status?: string
    last_checkup?: string
    total_expense?: number
    notes?: string
}

// 宠物API接口定义
export const PetApi = {
    // 获取宠物列表
    getPetList: (params: PetQuery) => {
        return api.get<PageData<PetInfo>>('/family/pet/list', { params })
    },

    // 用户获取一个家庭的宠物列表
    // 获取宠物列表
    UserGetPetList: (params: PetQuery) => {
        return api.get<PageData<PetInfo>>('/family/pet/user-pet/list', { params })
    },
    
    // 获取宠物详情
    getPetDetail: (id: number) => {
        return api.get<PetInfo>(`/family/pet/${id}`)
    },
    
    // 创建宠物
    createPet: (data: CreatePetRequest) => {
        return api.post<PetInfo>('/family/pet/create', data)
    },
    
    // 更新宠物
    updatePet: (id: number,  data:UpdatePetRequest) => {
        return api.put<PetInfo>(`/family/pet/${id}`, data)
    },
    
    // 删除宠物
    deletePet: (id: number) => {
        return api.delete(`/family/pet/${id}`)
    }
}